home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / WINPROGS.ARJ / SYSMETS1.C < prev    next >
Text File  |  1990-11-23  |  3KB  |  122 lines

  1. /*   sysmets1.C   -  System Metrics Display Program  
  2.                      Petzold
  3. */
  4.  
  5. #include <windows.h>
  6. #include "sysmets.h"
  7.  
  8. long FAR PASCAL WndProc (HWND, WORD, WORD, LONG);
  9.  
  10. int PASCAL WinMain (HANDLE hInstance,
  11.                     HANDLE hPrevInstance,
  12.                     LPSTR  lpszCmdParam,
  13.                     int    nCmdShow)
  14.                     
  15.   {
  16.   static char szAppName[] = "sysmets1";
  17.   HWND        hwnd;
  18.   MSG         msg;
  19.   WNDCLASS    wndclass;
  20.   
  21.   if (!hPrevInstance)
  22.      {
  23.      wndclass.style            = CS_HREDRAW | CS_VREDRAW;
  24.      wndclass.lpfnWndProc      = WndProc;
  25.      wndclass.cbClsExtra       = 0;
  26.      wndclass.cbWndExtra       = 0;
  27.      wndclass.hInstance        = hInstance;
  28.      wndclass.hIcon            = LoadIcon (NULL, IDI_APPLICATION);
  29.      wndclass.hCursor          = LoadCursor (NULL, IDC_ARROW);
  30.      wndclass.hbrBackground    = GetStockObject (WHITE_BRUSH);
  31.      wndclass.lpszMenuName     = NULL;
  32.      wndclass.lpszClassName    = szAppName;
  33.      
  34.      RegisterClass(&wndclass);
  35.      }
  36.      
  37.   hwnd = CreateWindow (szAppName,
  38.                        "Get System Metrics No. 1",
  39.                        WS_OVERLAPPEDWINDOW,
  40.                        CW_USEDEFAULT,   
  41.                        CW_USEDEFAULT,
  42.                        CW_USEDEFAULT,   
  43.                        CW_USEDEFAULT,   
  44.                        NULL,
  45.                        NULL,
  46.                        hInstance,
  47.                        NULL);
  48.                        
  49.   ShowWindow (hwnd, nCmdShow);
  50.   UpdateWindow (hwnd);
  51.   
  52.   while (GetMessage (&msg, NULL, 0, 0))
  53.     {
  54.     TranslateMessage (&msg);
  55.     DispatchMessage  (&msg);
  56.     }
  57.     
  58.   return msg.wParam;
  59.   }
  60.   
  61. long FAR PASCAL WndProc (HWND hwnd,
  62.                          WORD message,
  63.                          WORD wParam,
  64.                          LONG lParam)
  65.                          
  66.   {
  67.   static short cxChar, cxCaps, cyChar;
  68.   char         szBuffer[10];
  69.   short        i;
  70.   TEXTMETRIC   tm;
  71.   HDC          hdc;
  72.   PAINTSTRUCT  ps;
  73.   
  74.   switch (message)
  75.     {
  76.     case WM_CREATE:
  77.       hdc = GetDC (hwnd);
  78.       
  79.       GetTextMetrics (hdc, &tm);
  80.       cxChar = tm.tmAveCharWidth;
  81.       cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar /2;
  82.       cyChar = tm.tmHeight + tm.tmExternalLeading;
  83.       
  84.       ReleaseDC (hwnd, hdc);
  85.       return 0;
  86.       
  87.     case WM_PAINT:
  88.       hdc = BeginPaint (hwnd, &ps);
  89.  
  90.       for (i = 0; i < NUMLINES; i++)
  91.         {
  92.         TextOut (hdc, cxChar, cyChar *(1+i),
  93.                  sysmetrics[i].szLabel,
  94.                  lstrlen (sysmetrics[i].szLabel));
  95.  
  96.         TextOut (hdc, cxChar + 18 * cxCaps, cyChar *(1+i),
  97.                  sysmetrics[i].szDesc,
  98.                  lstrlen (sysmetrics[i].szDesc));
  99.                  
  100.          SetTextAlign (hdc, TA_RIGHT | TA_TOP);
  101.          
  102.          TextOut (hdc, cxChar + 18 * cxCaps + 40 * cxChar,
  103.                   cyChar * (1+i),
  104.                   szBuffer,
  105.                   wsprintf(szBuffer, "%5d",
  106.                            GetSystemMetrics (sysmetrics[i].nIndex)));
  107.                            
  108.          SetTextAlign (hdc, TA_LEFT | TA_TOP);                           
  109.          }
  110.          
  111.        EndPaint (hwnd, &ps);
  112.        return 0;
  113.          
  114.     case WM_DESTROY:
  115.       PostQuitMessage (0);
  116.       return 0;
  117.     }
  118.     
  119.   return DefWindowProc (hwnd, message, wParam, lParam);
  120.   }
  121.                   
  122.